<template>
  <div>
    <el-form :inline="true" :model="dataForm">
      <el-form-item label="关键字">
        <el-input v-model="dataForm.searchText" placeholder="关键字" clearable></el-input>
      </el-form-item>
      <el-form-item label="日期">
        <el-date-picker v-model="dataForm.createTimeStr" type="daterange" range-separator="至"
          start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getFormList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="tableData"
      row-key="formList"
      border size="mini"
      height="350px"
      style="width: 100%;">
      <el-table-column fixed="left" prop="stockName" label="库存地" min-width="150">
      </el-table-column>
      <el-table-column fixed="left" prop="stockTypeName" label="库存类型" min-width="150">
      </el-table-column>
      <el-table-column fixed="left" prop="payTypeText" label="支付方式" min-width="100">
      </el-table-column>
      <el-table-column fixed="left" prop="saleNum" label="重量（）" min-width="200">
      </el-table-column>
      <el-table-column fixed="left" prop="totalMoney" label="金额（元）" min-width="200">
      </el-table-column>
      <el-table-column prop="id" header-align="center" align="center" width="200" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="editInfoHandle(scope.row.id)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页信息 -->
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="total"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!--弹窗-->
    <addInfo v-if="addVisible" ref="addInfo" @refreshDataList="saleListPage"></addInfo>

  </div>
</template>

<script>
  import AddInfo from './updateSaleInfo'

  export default {
    name: 'saleList',
    data () {
      return {
        tableData: [],
        dataForm: {
          searchText: '',
          createTimeStr: ''
        },
        addVisible: false,
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        total: 0
      }
    },
    components: {
      AddInfo
    },
    activated () {
      this.init()
    },
    methods: {
      init () {
        this.initWarehouse()
        this.initStockDic()
        this.$nextTick(() => {
          this.saleListPage()
        })
      },
      saleListPage () {
        this.tableData = []
        this.$http({
          url: this.$http.adornUrl('/sale/saleListPage'),
          method: 'post',
          params: this.$http.adornParams({
            'partb': this.dataForm.searchText,
            'createTimeStr': this.dataForm.createTimeStr,
            'pageNumber': this.pageIndex,
            'pageSize': this.pageSize
          }, false)
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.tableData = data.data.data
            this.totalPage = data.data.pages
            this.total = data.data.total
          } else {
            this.tableData = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        }, false)
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.saleListPage()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.saleListPage()
      },
      initWarehouse () {
        this.$http({
          url: this.$http.adornUrl('/sale/warehouseList'),
          method: 'post',
          params: this.$http.adornParams({}, false)
        }).then(({data}) => {
          if (data && data.code === 0) {
            let warehouseList = data.data.data
            sessionStorage.setItem('warehouseList', JSON.stringify(warehouseList))
          }
        }, false)
      },
      initStockDic () {
        this.$http({
          url: this.$http.adornUrl('/sale/stockTypeList'),
          method: 'post',
          params: this.$http.adornParams({}, false)
        }).then(({data}) => {
          if (data && data.code === 0) {
            let stockTypeList = data.data.data
            sessionStorage.setItem('stockTypeList', JSON.stringify(stockTypeList))
          }
        }, false)
      },
      editInfoHandle (id) {
        console.log('--------------------------')
        console.log(id)
        this.addVisible = true
        this.$nextTick(() => {
          this.$refs.addInfo.init(id)
        })
      }
    }
  }
</script>

<style scoped>

</style>
